

import {observable , computed,action ,autorun} from "mobx"
import {fromJS} from "immutable"
import {ajax} from "@/utils/request"
class Data{
   @observable count = 2107;
   @observable city = '北京上海';
   @observable word = "wh2107-daydayup"
   @observable flag = true ;
   @observable mydata = fromJS({
     text:"Missyou",
     movie:[]
   })

  //  set 修改设置初始值 
   @computed get newCount(){
     return this.count * 10 + 8888;
   }

  //监听值的主动改变  
   set newCount(v){ 
       this.count = v / 10;
   }

   @action changeNewCount = num =>{
     this.newCount = num ; 
   }

   @action countAdd = ()=>{
     this.count+=1;
     console.log(this.count)
   }

   @action countDesc = ()=>{
     this.count-=1;
   }

   @action changeCount=payload=>{
     this.count+=payload; 
   }
   @action changeCity=city=>{
    this.city = city;  
  }
  @action changeWord = word =>{
    this.word = word;  
  }
  @action changeFlag = () =>{
    this.flag  = !this.flag ;  
  }

  @action  changeText = async ()=>{
     let res = await ajax.get("http://localhost:4400/api/test")
     console.log(res)
     this.mydata =  this.mydata.set("text",res.data.result)
  }

  @action changeMove = async ()=>{
    let res = await ajax.get("http://localhost:4400/movie")
    this.mydata = this.mydata.set("movie",res.data.result)
  }

  async getText(){
    let res = await  ajax.get("http://localhost:4400/api/test")
    return res;
  }
}

export default new Data() 